import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path';
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default defineConfig({
  publicDir: './public',
  base: './',
  envDir: './', // .env 环境变量地址
  plugins: [vue(), Components({
    resolvers: [
      ElementPlusResolver()
    ],
  })], // 配置需要使用的插件列表，这里将vue添加进去
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: `@import "${resolve(__dirname, 'src/less/default.less')}";`
      },
    }
  },
  build: {
    target: "es2015"
  },
  server: {
    host: "0.0.0.0",
    port: 8866,
    // https: false,
    proxy: {
      '/api': {
        target: 'http://localhost:8889/',
        changeOrigin: true,
        ws: true,
        rewrite: (pathStr) => pathStr.replace(/^\/api/, '')
      },
    },
  }
});